package com.example.bledemo.net;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Peter_Z.
 * <p>
 * Date: 2025/8/5 0005
 */
public class ApiHelper {
    public static <T> void request(Call<T> call, ApiCallback<T> callback) {
        call.enqueue(new Callback<T>() {
            @Override
            public void onResponse(Call<T> call, Response<T> response) {
                if (response.isSuccessful() && response.body() != null) {
                    callback.onSuccess(response.body());
                } else {
                    callback.onError(new Exception("请求失败: " + response.code()+"reason:"+response.body()));
                }
            }

            @Override
            public void onFailure(Call<T> call, Throwable t) {
                callback.onError(t);
            }
        });
    }
}